package objects;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class MovieSet {
	
	private String name = "MovieSet";
	private Set<Movie> storedMovies = null;
	
	public MovieSet(Set<Movie> movies) {
		storedMovies = new HashSet<Movie>(movies);
	}

	public MovieSet(List<Movie> movies) {
		storedMovies = new HashSet<Movie>(movies);
	}
	
	public  MovieSet() {
		storedMovies = new HashSet<Movie>();
	}

	public Set<Movie> getStoredMovies() {
		return storedMovies;
	}
	
	public MovieSet withAdded(Movie movie) {
		MovieSet movie2 = new MovieSet(storedMovies);
		movie2.storedMovies.add(movie);
		return movie2;
	}

	
	public MovieSet without(Movie user) {
		MovieSet movieSet2 = new MovieSet(storedMovies);
		movieSet2.storedMovies.remove(user);
		return movieSet2;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result
				+ ((storedMovies == null) ? 0 : storedMovies.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MovieSet other = (MovieSet) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (storedMovies == null) {
			if (other.storedMovies != null)
				return false;
		} else if (!storedMovies.equals(other.storedMovies))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "MovieSet [name=" + name + ", storedMovies=" + storedMovies
				+ "]";
	}

	public int size() {
		return storedMovies.size();
	}
	
}
